import { ref, reactive, onMounted, watch } from 'vue'
import { EditType } from '@/type/BaseEnum'
import useInstance from '@/hooks/useInstance'
import { useRouter, useRoute } from 'vue-router'

import { getGroupSelfPrimingApi } from '@/api/order'
import { GroupPointParm } from '@/api/order/MangeModel'
export default function useAddRessModel() {
	const router = useRouter()
	const route = useRoute()
	const flagmark = ref<any>(0)
	const hasMore = ref(true)
	const currentSelect = ref<any>(null)
	const newdata = ref<any>()
	const newrow = ref<any>()
	const groupbuy_id = ref<number | string>()
	//表格数据
	const listData = reactive({
		list: [] as any
	})
	//列表查询的参数
	const listParm = reactive<GroupPointParm>({
		pagesize: 10,
		page: 1,
		groupbuy_id: 0,
		count: 0
	})
	//获取全局属性
	const { global } = useInstance()
	//新增
	const addBtn = () => {}
	//编辑
	const editBtn = (row: any) => {}

	const getList = async (parm: GroupPointParm) => {
		let res = await getGroupSelfPrimingApi(parm)
		if (res && res.code == 0) {
			const { list, count } = res.result
			if (list && list.length <= 0) return (hasMore.value = false)
			listData.list = listData.list.concat(list)
			listParm.count = count
		}
	}
	const reFresh = () => {
		listData.list = []
		listParm.page = 1
		getList(listParm)
		if (flagmark.value == 1) {
			router.go(-1)
		}
	}
	const loadMore = async (done: any) => {
		listParm.page = (listParm.page as number) * 1 + 1
		await getList(listParm)
		done()
	}
	const getGrouppbuy = (n: any) => {
		listParm.groupbuy_id = n.groupbuy_id
		newrow.value = n
		getList(listParm)
	}
	const reset = () => {
		listParm.pagesize = 10
		listParm.page = 1
		listParm.groupbuy_id = 0
		listData.list = []
		currentSelect.value = null
	}

	const choseAddress = (address: any) => {
		currentSelect.value = address.id
		newdata.value = address
	}

	onMounted(() => {})
	return {
		getList,
		addBtn,
		editBtn,
		reFresh,
		listData,
		listParm,
		hasMore,
		loadMore,
		reset,
		newdata,
		flagmark,
		getGrouppbuy,
		currentSelect,
		choseAddress,
		newrow
	}
}
